package com.windoent.yugioh.adapter.brvah.multi;

import android.widget.LinearLayout;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.windoent.yugioh.R;
import com.windoent.yugioh.bean.multi.FeedbackUpLoadImageBean;
import com.windoent.yugioh.utils.SimpleUtils;
import com.windoent.yugioh.widget.RoundImageView;

/**
 * author : hp
 * date   : 2021-5-02 11:25
 * desc   :
 */
public class SettingImageUpLoadAdapter extends BaseMultiItemQuickAdapter<FeedbackUpLoadImageBean, BaseViewHolder> {

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     */
    public SettingImageUpLoadAdapter() {
        super(null);
        addItemType(0, R.layout.item_set_feedback_image_up_group);
        addItemType(1, R.layout.item_set_feedback_image_up_footer_view);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, FeedbackUpLoadImageBean item) {
        switch (helper.getItemViewType()) {
            case 0:
                RoundImageView image = helper.getView(R.id.image);
                LinearLayout llDelete = helper.getView(R.id.ll_delete);
                int layoutPosition = helper.getLayoutPosition();
                SimpleUtils.loadImageForView(getContext(), image, item.getUrl(), R.drawable.drawable_no_data);
                llDelete.setOnClickListener(view1 -> {
                    if (listener != null) {
                        listener.onDeletePicItemClick(layoutPosition);
                    }
                });
                break;
            case 1:
                RoundImageView imageView = helper.getView(R.id.image);
                imageView.setBackgroundResource(R.drawable.drawable_feedback_select_photo);
                break;
            default:
                break;
        }
    }

    //接口回调
    public interface onDeletePicItemClickListener {
        void onDeletePicItemClick(int position);
    }

    onDeletePicItemClickListener listener;

    public void setDeleteItemClickListener(onDeletePicItemClickListener listener) {
        this.listener = listener;
    }
}
